package sept.jasonparser2;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URI;


import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.util.Log;

import com.google.gson.Gson;


public class SearchResponse {
/*  public List<Result> results;
    
    @SerializedName("max_id")
    public long maxId;
    
    @SerializedName("since_id")
    public int sinceId;
    
    @SerializedName("refresh_url")
    public String refreshUrl;
    
    @SerializedName("next_page")
    public String nextPage;
    
    @SerializedName("results_per_page")
    public int resultsPerPage;
    
    public int page;
    
    @SerializedName("completed_in")
    public double completedIn;
    
    @SerializedName("since_id_str")
    public String sinceIdStr;
    
    @SerializedName("max_id_str")
    public String maxIdStr;
    
    public String query;*/
    
    public InputStream getJSONData(String url) {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        URI uri;
        InputStream data = null;
        try {
            uri = new URI(url);
            HttpGet method = new HttpGet(uri);
            HttpResponse response = httpClient.execute(method);
            data = response.getEntity().getContent();
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return data;
    }
    
    public void runJSONParser() {
        try {
            Log.i("MY INFO", "Json Parser Started..");
            Gson gson = new Gson();
            Reader r = new InputStreamReader
                    (getJSONData("http://search.twitter.com/trends.json"));
            Log.i("MY INFO", r.toString());
            TwitterTrends objs = gson.fromJson(r, TwitterTrends.class);
            Log.i("MY INFO", "" + objs.getTrends().size());
            for (TwitterTrend tr : objs.getTrends()) {
                Log.i("TRENDS", tr.getName() + tr.getUrl());
            }
            
            
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
}
